/**
 * Created by hiibook on 2017/6/15.
 */
var mysql  = require('mysql');
var config=require("../config/config");
module.exports=function (req,res,next) {

    console.log("mu发送用户列表");
    var connection = mysql.createConnection(config.mysql);
    connection.connect();
    var users={
        "msg": "ok",
        "data":[]
    };
    var query = connection.query('SELECT * FROM ss_user');
    query
        .on('error',function (err) {
            console.log('数据库连接失败',err)
        })
        .on('result',function (row) {

            connection.pause();
            users.data.push({
                "id" :row.id,
                "email":row.pass,
                "passwd":row.pass,
                "u": row.up_data,
                "d": row.down_data,
                "transfer_enable": row.transfer_enable,
                "port": row.id,
                "switch": row.switch,
                "enable": row.enable,
                "method": row.method

            });
            connection.resume();
        })
        .on('end',function () {
            if(users.data == [] ){
               console.log('用户数据获取失败')
            }else {
                res.json(users)
            }

        })

};